<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 变形平移的使用 -->
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html{
            perspective: 800px;
            transform-style: preserve-3d;
        }
        *{
            margin: 0;
            padding: 0;
        }

        .box{
            width: 100px;
            height: 100px;
        }
        #box1{
            /* 设置垂直居中的方式 */
            background: #2a0;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translateX(-50%) translateY(-50%);

        }
        #box2{
            /* 完成小米官网手机卡片上移效果 */
            background-color: pink;
            width: 240px;
            height: 400px;
            margin: 0 auto;
            margin-left: 1200px;
            margin-top: 100px;
        }
        #box2:hover{
            box-shadow: 0 0 10px rgba(0, 0, 0, .3);
            transform: translateY(-5%);
            transition: linear all 0.5s;
        }
        #box3{
            height: 400px;
            width: 400px;
            background-color: red;
            margin: 0 auto;
            margin-top: 100px;
            perspective: 800px;
            /* transform-style: preserve-3d; */
            /* overflow: hidden; */
        }
        #box4{
            width: 100px;
            height: 100px;
            background-color: #0b9;
            margin: auto;
            margin-top: 50%;
            transform-style: preserve-3d;
            transform: translateZ(0);
            transition:all 1s;
        }
        #box3:hover #box4{

            transform-style: preserve-3d;
            transform: translateZ(100px) translateX(100px);
        }
    </style>
</head>
<body>
    <div id="box1" class="box"></div>
    <div id="box2" class="box"></div>
    <!-- z轴平移实现视距的效果 -->
    <div id="box3"><div id="box4">
    </div></div>
    
</body>
</html>